
typedef struct _HashNode{
    int key;
    UT_hash_handle hh;
} HashNode;
typedef struct {
    HashNode *g_hashNode;
} RandomizedSet;
RandomizedSet* randomizedSetCreate() {
    RandomizedSet *obj = (RandomizedSet*)malloc(sizeof(RandomizedSet));
    memset(obj, 0, sizeof(RandomizedSet));
    return obj;
}
bool randomizedSetInsert(RandomizedSet* obj, int val) {
    HashNode *s = NULL;
    HASH_FIND_INT(obj->g_hashNode, &val, s);
    if (s != NULL) {
        return false;
    }
    s = (HashNode*)malloc(sizeof(HashNode));
    s->key = val;
    HASH_ADD_INT(obj->g_hashNode, key, s);
    return true;
}
bool randomizedSetRemove(RandomizedSet* obj, int val) {
    HashNode *hash = NULL;
    HASH_FIND_INT(obj->g_hashNode, &val, hash);
    if (hash == NULL) {
        return false;
    }
    HASH_DEL(obj->g_hashNode, hash);
    free(hash);
    return true;
}
int randomizedSetGetRandom(RandomizedSet* obj) {
    HashNode *cur = NULL;
    HashNode *tmp = NULL;
    int idx = 0;
    int cnt = 0;
    idx = rand() % (HASH_COUNT(obj->g_hashNode));
    HASH_ITER(hh, obj->g_hashNode, cur, tmp) {
        if (cnt++ >= idx) {
            break;
        }
    }
    return cur->key;
}

void randomizedSetFree(RandomizedSet* obj) {
    HashNode *cur = NULL;
    HashNode *tmp = NULL;
    HASH_ITER(hh, obj->g_hashNode, cur, tmp) {
        HASH_DEL(obj->g_hashNode, cur);
        free(cur);
    }
    free(obj);
}